package tester;

public class SingleQuestion extends Question{
	private int correctAnswer;
	
	public SingleQuestion (String questionText, String[] answers, String correctAnswer) {
		super(questionText, "Choose one answer: ", "\\s*\\d{1}\\s*", answers);
		this.correctAnswer = new Integer(correctAnswer);
	}
	
	private int convertAnswer(String answer) {
		answer.replaceAll("\\s", "");
		int result = new Integer(answer);
		return result;
	}
	
	@Override
	protected boolean checkAnswer(String answer) {
		if (!validateAnswer(this.regexp, answer)) {
			return false;
		}
		return (convertAnswer(answer) == this.correctAnswer);
	}
}
